<?php

class Controller
{
	protected $_model;
	protected $_controller;
	protected $_action;
	protected $_view;
	protected $_modelBaseName;
        protected $_productModel;
        protected $_categoryModel;
        protected $_memcached;
        protected $_peopleModel;
        protected $_imageModel;
        protected $_transactionModel;
        protected $_commentModel;


        public function __construct($model, $action)
	{
		$this->_controller = ucwords(__CLASS__);
		$this->_action = $action;
                $this->_imageModel = new imageModel();
                $this->_peopleModel = new peopleModel();
		$this->_modelBaseName = $model;
                $this->_transactionModel = new transactionModel();
		$this->_productModel = new productModel();
                $this->_categoryModel = new categoryModel();
                $this->_commentModel = new commentModel();
                $this->_memcached = new Memcache; 
                $this->_memcached->connect(MEMCACHED_SERVER, MEMCACHED_PORT) or die("Cannot connect to memcached server");
		$this->_view = new View(HOME . DS . 'application'. DS . 'views' . DS . strtolower($this->_modelBaseName) . DS . $action . '.html');
	}
	
	protected function _setModel($modelName)
	{
		$modelName .= 'Model';
		$this->_model = new $modelName();
		
	}
	
	protected function _setView($viewName)
	{
		$this->_view = new View(HOME . DS . 'application'. DS. 'views' . DS . strtolower($this->_modelBaseName) . DS . $viewName . '.html');
	}
        protected function getHeader()
        {
            if(!$this->_memcached->get('header'))
            {
                $content="";	

                $listcategory= $this->_categoryModel->getAllCate();
                $content .='<html>
            <head>
                <title>Ung dung dau gia</title>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <link rel="stylesheet" type="text/css" href="/public/style/style.css" />
                <link rel="stylesheet" type="text/css" href="/public/style/layout.css" />
                <link rel="stylesheet" href="/public/style/jquery-ui.css" />
               <link href="http://fonts.googleapis.com/css?family=Noto+Sans&subset=latin,vietnamese"rel="stylesheet" type="text/css">
                <script src="/public/js/jquery/jquery-1.8.3.min.js"></script>
                <script src="/public/js/jquery/jquery-ui.js"</script>
                <script src="/public/js/comment.js"></script>
                <script src="/public/js/search.js"></script>
             
            </head>
                <body>
                <div id="wrapper_homepage">
                        <script>
                    $(document).ready(function(){
                        $("#linkTimKiem").click(function(){
                            $("#boxSearch").toggle();
                        });
                    });
                </script>


                <div id="wrapper_header">
                    <a href="/home"><img id="imgHome" src="/public/images/Home-64.png" alt="Homepage" /></a>
                    <select id="selCategory" onchange="javascript:sort_onchange()">
                        <option value="0">chọn tất cả</option>';
                                        foreach ($listcategory as $item)
                                        {
                                $content .= '<option value="'.$item['idCategory'].'">'.$item['name'].'</option>';

                                        }

                                $content .= 
                   '</select>
                    <a id="linkTimKiem">Tìm kiếm</a>
                    <!--Box tim kiem-->
    <form class="frmSearch" id="boxSearch">
<h4>TÌM KIẾM VẬT PHẨM</h4>
<div class="searchContent"> 
    <input name="EMAIL" class="tenvp" id="txtTenVP" placeholder="Tên vật phẩm"> <br>
    <div class="clear">
        <label>Thể Loại</label><br>
        <select title="Thể loại" id="SearchCategory">
            <option value="0">Chọn tất cả</option>';
                                        foreach ($listcategory as $item)
                                        {
                                $content .= '<option value='.$item['idCategory'].'>'.$item['name'].'</option>';

                                        }

                                $content .= '
        </select>
    </div>
    <div class="clear">
        <label>Ngày bắt đầu</label><br>
        <input type="text" class="DateStarEnd" id="dateStart" placeholder="Ngày bắt đầu">
        <span>   -</span>
        <input type="text" class="DateStarEnd" id= "dateStartEnd" placeholder="Ngày bắt đầu">
    </div>
    <div class="clear">
        <label>Ngày kết thúc</label><br>
        <input type="text" class="DateStarEnd" id="dateEnd" placeholder="Ngày kết thúc">
        <span>   -</span>
        <input type="text" class="DateStarEnd" id="dateEndEnd" placeholder="Ngày kết thúc">
    </div>
    <div class="clear">
        <a class="btnSearch" href="javascript:search_onchange()" >Tìm kiếm </a>
    </div> 
</div>

</form></div>' ;
                $content .='<div class="sort">
    	
                <select class="sorta" onchange="javascript:sort(0)"><option value="-1">-Thứ tự-</option>
                <option value="1">----Tăng dần----</option>
                <option value="2">----Giảm dần----</option>
                </select> 
                <select class="sortb"  onchange="javascript:sort(0)">
                <option value="-1">-Sắp xếp theo-</option>   
                <option value="1">Tên vật phẩm</option>
                <option value="2">Ngày bắt đầu</option>
                <option value="3">Ngày kết thúc</option>
                </select> 
                <span class="sapxep">Sắp xếp</span>
             </div>';     
                    $this->_memcached->set('header',$content);
            }
            return $this->_memcached->get('header');

        }
}